<?php
require_once __DIR__ . '/common/common.php';
$page=$_GET['page'];//获取页码
$op=$_GET['op'];
$name=$_GET['name'];
$phone=$_GET['phone'];
$mail=$_GET['mail'];
$role=$_GET['role'];
$str="role='$role' ";
if($name){
    $str.="AND name='$name' ";
}
if ($phone){
    $str.="AND phone='$phone' ";
}
if ($mail){
    $str.="AND mail='$mail' ";
}





$page=(int)$page;   //强转数据
if ($page<1)
{
    $page=1;        //当得到内容小于1 转数字 1
}
$start=($page-1)*10;   //计算每一页的起始位置
if($op=="fy"){
    $data=mysqli_query($mysql,"SELECT COUNT(*) AS count FROM `users_login`");
}elseif($op=="cx"){
    $data=mysqli_query($mysql,"SELECT COUNT(*) AS count FROM `users_login` WHERE $str ");
    //file_put_contents(WEB_ROOT.'/2.txt',"SELECT COUNT(*) AS count FROM `user` WHERE $str",FILE_APPEND);
}

$count=mysqli_fetch_assoc($data);
$count=$count['count'];
if($op=="fy"){
    $data=mysqli_query($mysql,"SELECT uid,name,phone,role,mail,time FROM `users_login` ORDER BY uid LIMIT $start,10 ");
}elseif($op=="cx"){
    $data=mysqli_query($mysql,"SELECT uid,name,phone,role,mail,time FROM `users_login` WHERE $str ");

}
$count=ceil($count/10);
//
$arr=array();
while($a=mysqli_fetch_assoc($data))
{
    $arr[]=$a;
}
mysqli_free_result($data);

echo json_encode(array('data'=>$arr, 'count'=>$count,'op'=>$op));
